<?php
require_once 'tablecontentcn.array.php';
require_once 'tablecontenten.array.php';

function initializeTable($weida_pdo) {
  global $initialize_contentCN_array;
  global $initialize_contentEN_array;

	if (!isInitialized($weida_pdo)) {
	  foreach ($initialize_contentCN_array as &$sql) {
      $weida_pdo->exec($sql);
    }
	  foreach ($initialize_contentEN_array as &$sql) {
      $weida_pdo->exec($sql);
    }
		setInitialized($weida_pdo, TRUE);
	}
}

function isInitialized($weida_pdo) {
	$stmt = $weida_pdo->prepare ('SELECT initialized_date AS date FROM `system_initialized`');
	$stmt->execute ();
	if ($stmt->rowCount () == 1) {
		return true;
	}
	return false;
}

function setInitialized($weida_pdo, $initialized) {
	if ($initialized === TRUE) {
		$stmt = $weida_pdo->prepare ('INSERT INTO `system_initialized` ( initialized_date ) VALUES ( \'' . time() . '\' )');
		$stmt->execute ();
	} else if ($initialized === FALSE) {
		$stmt = $weida_pdo->prepare ('DELETE FROM `system_initialized`');
		$stmt->execute ();
	}
}
?>